-
Notifications
You must be signed in to change notification settings - Fork 910
Implementing string and byte[] async response handlers. Porting over … #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* @param <ResponseT> Pojo response type. | ||
* @return AsyncResponseHandler instance. | ||
*/ | ||
static <ResponseT> AsyncResponseHandler<ResponseT, String> dumpToString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why "dump"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString was taken. I can rename it to toUtf8String and have a toString that takes a Charset though per your other suggestion.
|
||
@Override | ||
public void onNext(ByteBuffer byteBuffer) { | ||
invokeSafely(() -> baos.write(BinaryUtils.copyBytesFrom(byteBuffer))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must be going crazy because I can't find that this method actually exists. http://docs.oracle.com/javase/8/docs/api/?java/io/ByteArrayOutputStream.html What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to copyBytesFrom
, or can we just use array
since the output stream copies it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we can assume it's backed by an array or that array constitutes the entire contents of the byte buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess we would need to check if it hasArray
and preserve the indices if we were to do it.
|
||
@Override | ||
public String complete() { | ||
return new String(byteArrayResponseHandler.complete(), StandardCharsets.UTF_8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is their data, we should probably make them define the encoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I'll add that.
|
||
if (msg instanceof StreamedHttpResponse) { | ||
requestContext.handler().onStream(new PublisherAdapter((StreamedHttpResponse) msg, channelContext, requestContext)); | ||
} else if (msg instanceof FullHttpResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fix all of the remaining empty-response integration test failures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, should fix them.
} | ||
|
||
@SafeVarargs | ||
private static void removePerRequestHandlers(ChannelHandlerContext ctx, Class<? extends ChannelHandler>... handlerClasses) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be varargs anymore? I only see one use. It could even be inlined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah I can inline it. Copied it from my other branch which removes some timeout handlers but didn't port that over.
@@ -134,20 +196,18 @@ public void onNext(HttpContent httpContent) { | |||
|
|||
@Override | |||
public void onError(Throwable t) { | |||
subscriber.onError(t); | |||
runAndLogError("Subsriber#onError threw an exception", () -> subscriber.onError(t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subsriber -> Subscriber (here and elsewhere). Will the subscriber be the customer's? Could it be beneficial to log which one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes in this context it will be the customers subscriber. Were you thinking like a class name or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, a class name or just calling toString on it. We could implement useful toStrings for our internal implementations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for toString, I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
b4d4bb5
to
1376635
Compare
* Creates an {@link AsyncResponseHandler} that writes all content to UTF8 encoded string. | ||
* | ||
* @param <ResponseT> Pojo response type. | ||
* @return AsyncResponseHandler instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param charset + other javadoc changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the minor other comments.
* @param <ResponseT> Pojo response type. | ||
*/ | ||
@SdkInternalApi | ||
class StringAsyncResponseHandler<ResponseT> implements AsyncResponseHandler<ResponseT, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString()?
* @param <ResponseT> Pojo response type. | ||
*/ | ||
@SdkInternalApi | ||
class ByteArrayAsyncResponseHandler<ResponseT> implements AsyncResponseHandler<ResponseT, byte[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually the subscriber we call toString on. Since the byte subscriber didn't have any identifying state I just left it as the default implementation. I can change it to whatever though, just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, it's aight.
1376635
to
bba549c
Compare
…temp fixes so PutObject will work
bba549c
to
5ff3309
Compare
…temp fixes so PutObject will work